$(document).ready(function() {
    $("#form_type").change(function() { //dectect change of select
        var type = $(this).val();
        //gửi lên hàm TypeSetParents lay gia tri parents
        $.ajax({
            type: 'post',
            url: 'http://localhost/fuelphp-ml/public/categories/typesetparents', //xem lại cách hiển thị link
            data: {"type": type},
            dataType: 'json',
            timeout: 10000,
            error: function(xhr, status, error) {
                alert('Error: ' + xhr.status + ' - ' + error);
            },
            success: function(response) {

                $("#form_parent_id").html('');
                for (var key in response) {
                $("#form_parent_id").append('<option value=' + key + '>' + response[key] + '</option>');
                }
                console.log(response, typeof(response));
            }
        });

    });
});